<?php

namespace App\Http\Requests\Logic\Company;

use App\Models\System\Admin;
use Illuminate\Validation\Rule;
use Illuminate\Support\Facades\Auth;
use Illuminate\Foundation\Http\FormRequest;

/**
 * 更新企业信息表单
 *
 * Date: 2018/5/30
 * @author George
 * @package App\Http\Requests\Logic\Company
 */
class UpdateResource extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
		$user = Auth::user();
    	if ($user instanceof Admin || $this->company->creator_id == $user->id) {
			return true;
		}
		return false;
    }

	/**
	 * 定义验证规则
	 *
	 * Date: 23/03/2018
	 * @author George
	 * @return array
	 */
    public function rules()
    {
        return [
        	'status' => [
        		'required',
				Rule::in(array_keys(config('system.approve')))
			]
        ];
    }

	/**
	 * 定义验证错误消息
	 *
	 * Date: 23/03/2018
	 * @author George
	 * @return array
	 */
	public function messages()
	{
		return [
			'status.required' => '请选择状态',
			'status.in' => '状态值错误',
		];
    }
}
